package _04file

import _03oop.Person
import groovy.json.JsonOutput
import groovy.json.JsonSlurper

//将对象转换成json
def personList = [new Person(name: 'fauks', age: 11),
                  new Person(name: 'bob', age: 13)]
def jsonArray = JsonOutput.toJson(personList)
println jsonArray

//将json转成对象
def jsonPerson = "{\"age\":101,\"name\":\"jay\"}"
def slurper = new JsonSlurper()
Person p = slurper.parseText(jsonPerson)
println p.name